/**
  ******************************************************************************
  * @file    usbd_cdc.c
  * @author  MCD Application Team
  * @brief   This file provides the high layer firmware functions to manage the
  *          following functionalities of the USB CDC Class:
  *           - Initialization and Configuration of high and low layer
  *           - Enumeration as CDC Device (and enumeration for each implemented memory interface)
  *           - OUT/IN data transfer
  *           - Command IN transfer (class requests management)
  *           - Error management
  *
  *  @verbatim
  *
  *          ===================================================================
  *                                CDC Class Driver Description
  *          ===================================================================
  *           This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
  *           Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
  *           Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
  *           This driver implements the following aspects of the specification:
  *             - Device descriptor management
  *             - Configuration descriptor management
  *             - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
  *             - Requests management (as described in section 6.2 in specification)
  *             - Abstract Control Model compliant
  *             - Union Functional collection (using 1 IN endpoint for control)
  *             - Data interface class
  *
  *           These aspects may be enriched or modified for a specific user application.
  *
  *            This driver doesn't implement the following aspects of the specification
  *            (but it is possible to manage these features with some modifications on this driver):
  *             - Any class-specific aspect relative to communication classes should be managed by user application.
  *             - All communication classes other than PSTN are not managed
  *
  *  @endverbatim
  *
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                      http://www.st.com/SLA0044
  *
  ******************************************************************************
  */

  /* BSPDependencies
  - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
  - "stm32xxxxx_{eval}{discovery}_io.c"
  EndBSPDependencies */

/* Includes ------------------------------------------------------------------*/
#include "usbd_cdc.h"
#include "usbd_ctlreq.h"
#include "adc_volt.h"
#include "main.h"
#include "debug.h"
#include "SSD2832.h"
#include "fsmc.h"
#include "ics307.h"
#include "ad5274_5271.h"
#include "InternalFlash.h"
#include "usart.h"
#include "SPI_INIT.h"  
#include "mtp_pwm.h"
#include "../DEMURA/Demura.h"
#include "../DDIC/AllDDIC.h"
#include "SD_Write.h"
#include "OuadSPI.h"
//u32 Demura_START_FLAG=0;
u8  Demura_OLEDModule_flag=0;
u8 DemuraIctype=0;
//u8 buffPowerR[21];	//返回ELVDD及功耗相关参数用
u16 crc16_data1 = 0;
//-----------------------------------Version Set--------------------------------------------
#define FW_Version      0x01
#define FW_SubVersion   0x09
//------------------------------------------------------------------------------------------
u8 NUM=0;
u8 DUAL_SPI_MODE = 0;
extern u16 RDAC;			//初始化VCI用
extern u16 RDAC_VDDIO;			//初始化VDDIO用
extern u16 RDAC_DVDD;
extern __ALIGN_BEGIN USBD_HandleTypeDef    USB_OTG_dev __ALIGN_END ;
u8 Valid_BMP_No = 0,PicShowedNum=0;
OLED_Para OLED;
u32 WriteAddress = Inter_Flash_Addr;
u32 buffer1[BMP_R_Byte_Max-1];
u8	Uart_rx_flag = REC_W_LCDCONF_FLAG;
u8  buffer[BMP_R_Byte_Max];
u32 i = 0,j = 0,k = 0;
u32 File_length=0;
u8 SendTo_PC_cfgFile=0;
u32 VCP_Receive_True_num=0;
u32 USB_Rx_Demura_Total_Num=0;
u32 USB_Tx_Demura_Num=0;
u32 USB_Rx_Demura_Total_Num_Temp=0;
u32 USB_Rx_Demura_Num=0;
u32 USB_Rx_Demura=0;
//u32 USB_Demura_Transmode_start=0;
u8 USB_Rx_Demura_End_Flag=0;
u32 DemuraRecivedNum=0;      //统计已经接收的数据数量
u32 DemuraTransOnce=0;        //每次传输的像素数量
u8  Demura_first_package_flag=0;  //首次发送标志
u32 Juewang=0;
u32 USB_Rx_2C3C=0;
u32 ICS307_Valid_Data=0;
u32 ICS307_Buf_Data=0;
u32 ICS307_Buf_Data1 = 0;
u8 PatternR=0,PatternG=0,PatternB=0;
u8 Pure_Color_Flag = 0;
u8 CS_Master = CS1;
u8 CS_Slaver = CS2;
u16 OLED_X0,OLED_X1,OLED_Y0,OLED_Y1,OLED_X_VALUE,OLED_Y_VALUE;
u16 LP_B7_Data,HS_B7_Data;
u8  Rec_first_line_Flag = 1;
u8 RM35x_otptime = 0;
u32 SSD28xx_Code[SSD2832_Code_Max];                         //保存SSD2832初始化代码
u32 SSD28xx_SCM_Data[SSD2832_SCM_Code_Max];                 //保存SSD2832 SCM REG Data
u16 SSD28xx_SCM_Cmd[SSD2832_SCM_Code_Max];									//保存SSD2832 SCM REG Cmd
u32 Timing_and_InitCode[IniCode_Max];                       //保存Timing&Driver IC代码
u8  SSD28xxCode_count = 0;                                  //
u8  SSD28xx_SCM_Code_count = 0; 
u8  InitCode_valid[IniCode_table_num][IniCode_Max];         //
//u16  InitCode_valid16[IniCode_table_num][IniCode_Max];
u8  Buffer_ReadCode[255];
u32 InitCode_count=0;                                       //
const u16 AD_Value1[8] = {0x01f0,0x0188,0x0134,0x00f0,0x00b4,0x0084,0x005c,0x0038};//0x03ff(2.3),0x032f(2.4),0x0278(2.5),0x0018(3.4),0x0000(3.5)
const u16 AD_Value2[4] = {0x018c,0x0110,0x00bc,0x007c};  //0x032c(1.6),0x022c(1.7),0x0048(2.2),0x001c(2.3)
const u16 AD_Value3[4] = {0xFFFF,0x0214,0x0164,0x00F8};  //1.0~1.3
u32 Code_length = 0;
u8  Receive_Code_flag = 0;

//u8  Demura_OLEDModule_flag=0;
u8  Receive_BIN_Flag = 0;
u8  Receive_BIN_Flag1 = 0;
u8  Receive_CFG_Flag1 = 0;
u8  Receive_BIN_Flag2 = 0;
u32 Receive_BIN_Length = 0;
u32 Receive_CFG_Length = 0;
u8 CFGorBMP=0;
u8 BMPnums = 0;
u32 bw;
u8 qflag=0;
u32  Device_ID_Buf[2];
u32  Device_ID = 2;
u32  Device_Addr = 0;
bool Power_ON_Flag=false;
double VCIc,VDDIOc,DVDDc;
//----------------------------------------------------------------------------------
u8 gamma_read_num=0;
u8 gamma_write_num=0;

__IO  uint8_t USB_StatusDataSended = 1;
__IO  uint32_t USB_ReceivedCount = 0;
/** @addtogroup STM32_USB_DEVICE_LIBRARY
  * @{
  */
__ALIGN_BEGIN uint8_t USB_Rx_Buffer   [CDC_DATA_HS_MAX_PACKET_SIZE] __ALIGN_END ;

/** @defgroup USBD_CDC
  * @brief usbd core module
  * @{
  */

/** @defgroup USBD_CDC_Private_TypesDefinitions
  * @{
  */
/**
  * @}
  */


/** @defgroup USBD_CDC_Private_Defines
  * @{
  */
/**
  * @}
  */


/** @defgroup USBD_CDC_Private_Macros
  * @{
  */

/**
  * @}
  */


/** @defgroup USBD_CDC_Private_FunctionPrototypes
  * @{
  */


static uint8_t  USBD_CDC_Init (USBD_HandleTypeDef *pdev,
                               uint8_t cfgidx);

static uint8_t  USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
                                 uint8_t cfgidx);

static uint8_t  USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
                                USBD_SetupReqTypedef *req);

static uint8_t  USBD_CDC_DataIn (USBD_HandleTypeDef *pdev,
                                 uint8_t epnum);

static uint8_t  USBD_CDC_DataOut (USBD_HandleTypeDef *pdev,
                                 uint8_t epnum);

static uint8_t  USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev);

static uint8_t  *USBD_CDC_GetFSCfgDesc (uint16_t *length);

static uint8_t  *USBD_CDC_GetHSCfgDesc (uint16_t *length);

static uint8_t  *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);

static uint8_t  *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);

uint8_t  *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length);

/* USB Standard Device Descriptor */
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
{
  USB_LEN_DEV_QUALIFIER_DESC,
  USB_DESC_TYPE_DEVICE_QUALIFIER,
  0x00,
  0x02,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
};

/**
  * @}
  */

/** @defgroup USBD_CDC_Private_Variables
  * @{
  */


/* CDC interface class callbacks structure */
USBD_ClassTypeDef  USBD_CDC =
{
  USBD_CDC_Init,
  USBD_CDC_DeInit,
  USBD_CDC_Setup,
  NULL,                 /* EP0_TxSent, */
  USBD_CDC_EP0_RxReady,
  USBD_CDC_DataIn,
  USBD_CDC_DataOut,
  NULL,
  NULL,
  NULL,
  USBD_CDC_GetHSCfgDesc,
  USBD_CDC_GetFSCfgDesc,
  USBD_CDC_GetOtherSpeedCfgDesc,
  USBD_CDC_GetDeviceQualifierDescriptor,
};

/* USB CDC device Configuration Descriptor */
__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
{
  /*Configuration Descriptor*/
  0x09,   /* bLength: Configuration Descriptor size */
  USB_DESC_TYPE_CONFIGURATION,      /* bDescriptorType: Configuration */
  USB_CDC_CONFIG_DESC_SIZ,                /* wTotalLength:no of returned bytes */
  0x00,
  0x02,   /* bNumInterfaces: 2 interface */
  0x01,   /* bConfigurationValue: Configuration value */
  0x00,   /* iConfiguration: Index of string descriptor describing the configuration */
  0xC0,   /* bmAttributes: self powered */
  0x32,   /* MaxPower 0 mA */

  /*---------------------------------------------------------------------------*/

  /*Interface Descriptor */
  0x09,   /* bLength: Interface Descriptor size */
  USB_DESC_TYPE_INTERFACE,  /* bDescriptorType: Interface */
  /* Interface descriptor type */
  0x00,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x01,   /* bNumEndpoints: One endpoints used */
  0x02,   /* bInterfaceClass: Communication Interface Class */
  0x02,   /* bInterfaceSubClass: Abstract Control Model */
  0x01,   /* bInterfaceProtocol: Common AT commands */
  0x00,   /* iInterface: */

  /*Header Functional Descriptor*/
  0x05,   /* bLength: Endpoint Descriptor size */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x00,   /* bDescriptorSubtype: Header Func Desc */
  0x10,   /* bcdCDC: spec release number */
  0x01,

  /*Call Management Functional Descriptor*/
  0x05,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x01,   /* bDescriptorSubtype: Call Management Func Desc */
  0x00,   /* bmCapabilities: D0+D1 */
  0x01,   /* bDataInterface: 1 */

  /*ACM Functional Descriptor*/
  0x04,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
  0x02,   /* bmCapabilities */

  /*Union Functional Descriptor*/
  0x05,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x06,   /* bDescriptorSubtype: Union func desc */
  0x00,   /* bMasterInterface: Communication class interface */
  0x01,   /* bSlaveInterface0: Data Class Interface */

  /*Endpoint 2 Descriptor*/
  0x07,                           /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,   /* bDescriptorType: Endpoint */
  CDC_CMD_EP,                     /* bEndpointAddress */
  0x03,                           /* bmAttributes: Interrupt */
  LOBYTE(CDC_CMD_PACKET_SIZE),     /* wMaxPacketSize: */
  HIBYTE(CDC_CMD_PACKET_SIZE),
  CDC_HS_BINTERVAL,                           /* bInterval: */
  /*---------------------------------------------------------------------------*/

  /*Data class interface descriptor*/
  0x09,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_INTERFACE,  /* bDescriptorType: */
  0x01,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x02,   /* bNumEndpoints: Two endpoints used */
  0x0A,   /* bInterfaceClass: CDC */
  0x00,   /* bInterfaceSubClass: */
  0x00,   /* bInterfaceProtocol: */
  0x00,   /* iInterface: */

  /*Endpoint OUT Descriptor*/
  0x07,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,      /* bDescriptorType: Endpoint */
  CDC_OUT_EP,                        /* bEndpointAddress */
  0x02,                              /* bmAttributes: Bulk */
  LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),  /* wMaxPacketSize: */
  HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
  0x00,                              /* bInterval: ignore for Bulk transfer */

  /*Endpoint IN Descriptor*/
  0x07,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,      /* bDescriptorType: Endpoint */
  CDC_IN_EP,                         /* bEndpointAddress */
  0x02,                              /* bmAttributes: Bulk */
  LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),  /* wMaxPacketSize: */
  HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
  0x00                               /* bInterval: ignore for Bulk transfer */
} ;


/* USB CDC device Configuration Descriptor */
__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
{
  /*Configuration Descriptor*/
  0x09,   /* bLength: Configuration Descriptor size */
  USB_DESC_TYPE_CONFIGURATION,      /* bDescriptorType: Configuration */
  USB_CDC_CONFIG_DESC_SIZ,                /* wTotalLength:no of returned bytes */
  0x00,
  0x02,   /* bNumInterfaces: 2 interface */
  0x01,   /* bConfigurationValue: Configuration value */
  0x00,   /* iConfiguration: Index of string descriptor describing the configuration */
  0xC0,   /* bmAttributes: self powered */
  0x32,   /* MaxPower 0 mA */

  /*---------------------------------------------------------------------------*/

  /*Interface Descriptor */
  0x09,   /* bLength: Interface Descriptor size */
  USB_DESC_TYPE_INTERFACE,  /* bDescriptorType: Interface */
  /* Interface descriptor type */
  0x00,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x01,   /* bNumEndpoints: One endpoints used */
  0x02,   /* bInterfaceClass: Communication Interface Class */
  0x02,   /* bInterfaceSubClass: Abstract Control Model */
  0x01,   /* bInterfaceProtocol: Common AT commands */
  0x00,   /* iInterface: */

  /*Header Functional Descriptor*/
  0x05,   /* bLength: Endpoint Descriptor size */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x00,   /* bDescriptorSubtype: Header Func Desc */
  0x10,   /* bcdCDC: spec release number */
  0x01,

  /*Call Management Functional Descriptor*/
  0x05,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x01,   /* bDescriptorSubtype: Call Management Func Desc */
  0x00,   /* bmCapabilities: D0+D1 */
  0x01,   /* bDataInterface: 1 */

  /*ACM Functional Descriptor*/
  0x04,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
  0x02,   /* bmCapabilities */

  /*Union Functional Descriptor*/
  0x05,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x06,   /* bDescriptorSubtype: Union func desc */
  0x00,   /* bMasterInterface: Communication class interface */
  0x01,   /* bSlaveInterface0: Data Class Interface */

  /*Endpoint 2 Descriptor*/
  0x07,                           /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,   /* bDescriptorType: Endpoint */
  CDC_CMD_EP,                     /* bEndpointAddress */
  0x03,                           /* bmAttributes: Interrupt */
  LOBYTE(CDC_CMD_PACKET_SIZE),     /* wMaxPacketSize: */
  HIBYTE(CDC_CMD_PACKET_SIZE),
  CDC_FS_BINTERVAL,                           /* bInterval: */
  /*---------------------------------------------------------------------------*/

  /*Data class interface descriptor*/
  0x09,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_INTERFACE,  /* bDescriptorType: */
  0x01,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x02,   /* bNumEndpoints: Two endpoints used */
  0x0A,   /* bInterfaceClass: CDC */
  0x00,   /* bInterfaceSubClass: */
  0x00,   /* bInterfaceProtocol: */
  0x00,   /* iInterface: */

  /*Endpoint OUT Descriptor*/
  0x07,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,      /* bDescriptorType: Endpoint */
  CDC_OUT_EP,                        /* bEndpointAddress */
  0x02,                              /* bmAttributes: Bulk */
  LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),  /* wMaxPacketSize: */
  HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
  0x00,                              /* bInterval: ignore for Bulk transfer */

  /*Endpoint IN Descriptor*/
  0x07,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,      /* bDescriptorType: Endpoint */
  CDC_IN_EP,                         /* bEndpointAddress */
  0x02,                              /* bmAttributes: Bulk */
  LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),  /* wMaxPacketSize: */
  HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
  0x00                               /* bInterval: ignore for Bulk transfer */
} ;

__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
{
  0x09,   /* bLength: Configuation Descriptor size */
  USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
  USB_CDC_CONFIG_DESC_SIZ,
  0x00,
  0x02,   /* bNumInterfaces: 2 interfaces */
  0x01,   /* bConfigurationValue: */
  0x04,   /* iConfiguration: */
  0xC0,   /* bmAttributes: */
  0x32,   /* MaxPower 100 mA */

  /*Interface Descriptor */
  0x09,   /* bLength: Interface Descriptor size */
  USB_DESC_TYPE_INTERFACE,  /* bDescriptorType: Interface */
  /* Interface descriptor type */
  0x00,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x01,   /* bNumEndpoints: One endpoints used */
  0x02,   /* bInterfaceClass: Communication Interface Class */
  0x02,   /* bInterfaceSubClass: Abstract Control Model */
  0x01,   /* bInterfaceProtocol: Common AT commands */
  0x00,   /* iInterface: */

  /*Header Functional Descriptor*/
  0x05,   /* bLength: Endpoint Descriptor size */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x00,   /* bDescriptorSubtype: Header Func Desc */
  0x10,   /* bcdCDC: spec release number */
  0x01,

  /*Call Management Functional Descriptor*/
  0x05,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x01,   /* bDescriptorSubtype: Call Management Func Desc */
  0x00,   /* bmCapabilities: D0+D1 */
  0x01,   /* bDataInterface: 1 */

  /*ACM Functional Descriptor*/
  0x04,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
  0x02,   /* bmCapabilities */

  /*Union Functional Descriptor*/
  0x05,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x06,   /* bDescriptorSubtype: Union func desc */
  0x00,   /* bMasterInterface: Communication class interface */
  0x01,   /* bSlaveInterface0: Data Class Interface */

  /*Endpoint 2 Descriptor*/
  0x07,                           /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT      ,   /* bDescriptorType: Endpoint */
  CDC_CMD_EP,                     /* bEndpointAddress */
  0x03,                           /* bmAttributes: Interrupt */
  LOBYTE(CDC_CMD_PACKET_SIZE),     /* wMaxPacketSize: */
  HIBYTE(CDC_CMD_PACKET_SIZE),
  CDC_FS_BINTERVAL,                           /* bInterval: */

  /*---------------------------------------------------------------------------*/

  /*Data class interface descriptor*/
  0x09,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_INTERFACE,  /* bDescriptorType: */
  0x01,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x02,   /* bNumEndpoints: Two endpoints used */
  0x0A,   /* bInterfaceClass: CDC */
  0x00,   /* bInterfaceSubClass: */
  0x00,   /* bInterfaceProtocol: */
  0x00,   /* iInterface: */

  /*Endpoint OUT Descriptor*/
  0x07,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,      /* bDescriptorType: Endpoint */
  CDC_OUT_EP,                        /* bEndpointAddress */
  0x02,                              /* bmAttributes: Bulk */
  0x40,                              /* wMaxPacketSize: */
  0x00,
  0x00,                              /* bInterval: ignore for Bulk transfer */

  /*Endpoint IN Descriptor*/
  0x07,   /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT,     /* bDescriptorType: Endpoint */
  CDC_IN_EP,                        /* bEndpointAddress */
  0x02,                             /* bmAttributes: Bulk */
  0x40,                             /* wMaxPacketSize: */
  0x00,
  0x00                              /* bInterval */
};

/**
  * @}
  */

/** @defgroup USBD_CDC_Private_Functions
  * @{
  */

/**
  * @brief  USBD_CDC_Init
  *         Initialize the CDC interface
  * @param  pdev: device instance
  * @param  cfgidx: Configuration index
  * @retval status
  */
static uint8_t  USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
  uint8_t ret = 0U;
  USBD_CDC_HandleTypeDef   *hcdc;

  if(pdev->dev_speed == USBD_SPEED_HIGH)
  {
    /* Open EP IN */
    USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
                   CDC_DATA_HS_IN_PACKET_SIZE);

    pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;

    /* Open EP OUT */
    USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
                   CDC_DATA_HS_OUT_PACKET_SIZE);

    pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;

  }
  else
  {
    /* Open EP IN */
    USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
                   CDC_DATA_FS_IN_PACKET_SIZE);

    pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;

    /* Open EP OUT */
    USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
                   CDC_DATA_FS_OUT_PACKET_SIZE);

    pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
  }
  /* Open Command IN EP */
  USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
  pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U;

  pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));

  if(pdev->pClassData == NULL)
  {
    ret = 1U;
  }
  else
  {
    hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

    /* Init  physical Interface components */
    ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();

    /* Init Xfer states */
    hcdc->TxState = 0U;
    hcdc->RxState = 0U;

    if(pdev->dev_speed == USBD_SPEED_HIGH)
    {
      /* Prepare Out endpoint to receive next packet */
      USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
                             CDC_DATA_HS_OUT_PACKET_SIZE);
    }
    else
    {
      /* Prepare Out endpoint to receive next packet */
      USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
                             CDC_DATA_FS_OUT_PACKET_SIZE);
    }
  }
  return ret;
}

/**
  * @brief  USBD_CDC_Init
  *         DeInitialize the CDC layer
  * @param  pdev: device instance
  * @param  cfgidx: Configuration index
  * @retval status
  */
static uint8_t  USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
  uint8_t ret = 0U;

  /* Close EP IN */
  USBD_LL_CloseEP(pdev, CDC_IN_EP);
  pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 0U;

  /* Close EP OUT */
  USBD_LL_CloseEP(pdev, CDC_OUT_EP);
  pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 0U;

  /* Close Command IN EP */
  USBD_LL_CloseEP(pdev, CDC_CMD_EP);
  pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;

  /* DeInit  physical Interface components */
  if(pdev->pClassData != NULL)
  {
    ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
    USBD_free(pdev->pClassData);
    pdev->pClassData = NULL;
  }

  return ret;
}

/**
  * @brief  USBD_CDC_Setup
  *         Handle the CDC specific requests
  * @param  pdev: instance
  * @param  req: usb requests
  * @retval status
  */
static uint8_t  USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
                                USBD_SetupReqTypedef *req)
{
  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
  uint8_t ifalt = 0U;
  uint16_t status_info = 0U;
  uint8_t ret = USBD_OK;

  switch (req->bmRequest & USB_REQ_TYPE_MASK)
  {
  case USB_REQ_TYPE_CLASS :
    if (req->wLength)
    {
      if (req->bmRequest & 0x80U)
      {
        ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
                                                          (uint8_t *)(void *)hcdc->data,
                                                          req->wLength);

          USBD_CtlSendData (pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
      }
      else
      {
        hcdc->CmdOpCode = req->bRequest;
        hcdc->CmdLength = (uint8_t)req->wLength;

        USBD_CtlPrepareRx (pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
      }
    }
    else
    {
      ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
                                                        (uint8_t *)(void *)req, 0U);
    }
    break;

  case USB_REQ_TYPE_STANDARD:
    switch (req->bRequest)
    {
    case USB_REQ_GET_STATUS:
      if (pdev->dev_state == USBD_STATE_CONFIGURED)
      {
        USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
      }
      else
      {
        USBD_CtlError (pdev, req);
			  ret = USBD_FAIL;
      }
      break;

    case USB_REQ_GET_INTERFACE:
      if (pdev->dev_state == USBD_STATE_CONFIGURED)
      {
        USBD_CtlSendData (pdev, &ifalt, 1U);
      }
      else
      {
        USBD_CtlError (pdev, req);
			  ret = USBD_FAIL;
      }
      break;

    case USB_REQ_SET_INTERFACE:
      if (pdev->dev_state != USBD_STATE_CONFIGURED)
      {
        USBD_CtlError (pdev, req);
			  ret = USBD_FAIL;
      }
      break;

    default:
      USBD_CtlError (pdev, req);
      ret = USBD_FAIL;
      break;
    }
    break;

  default:
    USBD_CtlError (pdev, req);
    ret = USBD_FAIL;
    break;
  }

  return ret;
}

/**
  * @brief  USBD_CDC_DataIn
  *         Data sent on non-control IN endpoint
  * @param  pdev: device instance
  * @param  epnum: endpoint number
  * @retval status
  */
static uint8_t  USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
{
  USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)pdev->pClassData;
  PCD_HandleTypeDef *hpcd = pdev->pData;

  if(pdev->pClassData != NULL)
  {
    if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
    {
      /* Update the packet total length */
      pdev->ep_in[epnum].total_length = 0U;

      /* Send ZLP */
      USBD_LL_Transmit (pdev, epnum, NULL, 0U);
    }
    else
    {
      hcdc->TxState = 0U;
    }
    return USBD_OK;
  }
  else
  {
    return USBD_FAIL;
  }
}

u32 BMP_START_FLAG=0;
u32 Demura_START_FLAG=0;
#define BMP_FLAG				0xBD

/**
  * @brief  USBD_CDC_DataOut
  *         Data received on non-control Out endpoint
  * @param  pdev: device instance
  * @param  epnum: endpoint number
  * @retval status
  */
static uint8_t  USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
{
	u16 i=0;u32 TotalNum=0;
	u16 temp_spi_num=0;	
	LED4_LOW;
	USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

	/* Get the received data length */
	hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);

	/* USB data will be immediately processed, this allow next USB traffic being
	NAKed till the end of the application Xfer */
	USB_OTG_dev = *pdev;
	if(epnum == (CDC_OUT_EP&0x7F))
	{
		USB_ReceivedCount = hcdc->RxLength;
		/* Prapare EP to Receive next Cmd */
		USBD_LL_PrepareReceive (pdev,CDC_OUT_EP,(uint8_t *)USB_Rx_Buffer,sizeof(hcdc->RxBuffer)); 
		if(USB_Rx_Buffer[0] == 0x66 && USB_Rx_Buffer[2] == 0x04 &&USB_Rx_Buffer[7] == 0xff&&USB_Rx_Buffer[8] == 0xff&&USB_ReceivedCount == 0x0c)
		{
			Receive_CFG_Flag1 = 1;
			if(USB_Rx_Buffer[1] == 0X01)
			{
				CFGorBMP = 1;
			}
			else if(USB_Rx_Buffer[1] == 0X02)
			{
				CFGorBMP = 0;
				BMPnums = USB_Rx_Buffer[9];
			}
				Receive_CFG_Length = (USB_Rx_Buffer[3]<<24)+(USB_Rx_Buffer[4]<<16)+(USB_Rx_Buffer[5]<<8)+USB_Rx_Buffer[6];
				USB_Rx_Buffer[4] = Uart_Error_None;
				STM2PC(pdev,CDC_IN_EP,USB_Rx_Buffer,USB_Rx_Buffer[2]+3);           //返回 写寄存器状态  ：ok 
		}
		if(Receive_CFG_Flag1 == 0)
		{
			if((BMP_START_FLAG==2)&&(USB_ReceivedCount>1))  //显示BMP,新版快速刷图
			{	
				if(OLED.SigMode == Video_Mode)  //RGB+SPI= MIPI
				{
					UsbBMPData2FPGAbyFSMC(USB_Rx_Buffer);
				}
				else if(OLED.SigMode == CMD_Mode)  //Command
				{
					for(i=0;i<USB_ReceivedCount;i++)
					buffer[i+VCP_Receive_True_num] = USB_Rx_Buffer[i]; 
					
					VCP_Receive_True_num+=USB_ReceivedCount;
					if(VCP_Receive_True_num == OLED.H_pixel*3 || VCP_Receive_True_num == OLED.H_pixel*2) // OLED.H_pixel*3
					{  
						SPI_CS_Select(CS_Master,0);
						SSD2828_W_RAM_buffer_8bits_part(OLED.pixel_clk,OLED.SigMode,buffer,OLED.H_pixel,1,0);
						SPI_CS_Select(CS_Master,1);
						
						VCP_Receive_True_num=0;
					}	
					
//					SPI_CS_Select(CS_Master,0);
//					SSD2828_W_RAM_buffer_CMD(OLED.pixel_clk,OLED.SigMode,buffer,OLED.H_pixel,1,0);
//					SPI_CS_Select(CS_Master,1);
				}
				else if((OLED.SigMode == SPI3_Mode)||(OLED.SigMode == SPI4_Mode))          //3线8bit SPI 模式   //4线8bit SPI 模式
				{    
					SPI_PANEL_WriteRAM_buffer_part(OLED.SigMode,CS_Master,buffer,OLED.H_pixel,1,Rec_first_line_Flag,DUAL_SPI_MODE,OLED.RGBMode);
					if(Rec_first_line_Flag == 1)
					Rec_first_line_Flag = 0;
				}  
				else if(OLED.SigMode ==QuadSPI_Mode)          //QuadSPI
				{
					for(i=0;i<USB_ReceivedCount;i++)
					buffer[i+VCP_Receive_True_num] = USB_Rx_Buffer[i]; 
					
					VCP_Receive_True_num+=USB_ReceivedCount;
					if(VCP_Receive_True_num == OLED.H_pixel*3 ) // OLED.H_pixel*3
					{  
						OuadSPI_WriteRAM_continue_part(OLED.SigMode,CS_Master,buffer,OLED.H_pixel,1,Rec_first_line_Flag,DUAL_SPI_MODE,OLED.RGBMode);
						VCP_Receive_True_num=0;
						if(Rec_first_line_Flag == 1)
							Rec_first_line_Flag = 0;
					
					}
				}
			}

			else if((USB_Rx_Buffer[0]==0X5A)&&(USB_ReceivedCount==1)) //显示BMP结束
			{			
				NUM=0;
				{            
					BMP_START_FLAG=0;//BMP_END_FLAG=0;
			//		FPGA_Fifo0Wen_LOW;
					if(OLED.SigMode == Video_Mode)
					{
						Load_done_HIGH;
						FSMC_BMP_NUM(Valid_BMP_No);                     //当前画面序号
					}
					else if(OLED.SigMode == CMD_Mode)
					{
						SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,LP_B7_Data);			
					}
					else if(OLED.SigMode == QuadSPI_Mode)          //QuadSPI_Mode
					{
					 OuadSPI_CS_H();
					}
					STM2PC_ERROR(pdev,CDC_IN_EP,0x0A,0x03,Uart_Error_None,0);           //返回 写LCD_Config状态  ：ok 
				}
			}      
			else if((Demura_START_FLAG==1)&&(USB_ReceivedCount>1))  //Demura 数据搬入
			{			
				DemuraData2DDICRam(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,buffer,LP_B7_Data,HS_B7_Data);
			}
			else if((Demura_START_FLAG==2)&&(USB_ReceivedCount>1))  //兼容旧版的新Demura 数据搬入
			{			
				Write_Data_to_Demura_RAM(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,buffer,LP_B7_Data,HS_B7_Data);
			}
			else //if(USB_ReceivedCount>1)
			{
				if ( (USB_ReceivedCount<510)&& ( (USB_Rx_Buffer[1]&0xc0) >0) ) //----新指令格式/协议专用
				{//如果此时传过来的不是图片数据，且标志位USB_Rx_Buffer[1]的高两位大于0：此时指令格式为新版
					TotalNum=(USB_Rx_Buffer[2]+((USB_Rx_Buffer[1]&0xc0)>>6)*128);
				}//
				else TotalNum=0;//----新指令格式/协议专用
				if((USB_ReceivedCount==REC_LCDCONF_NUM)&&(USB_Rx_Demura==0)&&(NUM==0)&&(Receive_BIN_Flag == 0)&&(Receive_BIN_Flag1 == 0))      
				{//接受固定数据长度  
					if(USB_Rx_Buffer[0]==REC_LCDCONF_START||USB_Rx_Buffer[0]==REC_LCDCONF_CONVERT||USB_Rx_Buffer[0]==REC_LCDCONF_POWER_ON)         //上位机 发送模组Timing参数、ICS307配置参数、通道数  0X0A
					{
						Uart_rx_flag = USB_Rx_Buffer[1]; //功能标志
						crc16_data = crc16(USB_Rx_Buffer,USB_Rx_Buffer[2]+4-2,0xFFFF);
						if(crc16_data == ((USB_Rx_Buffer[USB_Rx_Buffer[2]+4-2]<<8)|(USB_Rx_Buffer[USB_Rx_Buffer[2]+4-1])))
						{
							if(REC_W_LCDCONF_FLAG == Uart_rx_flag)		//上位机 发送 LCDConfig 数据
							{ 	
								VPP_POWER_Init(0.0,OTP_Disable);	
								if(Power_ON_Flag==false)
								{
									VDDIO_EN_HIGH;	
									delay_ms(2);
									if(RDAC_DVDD == 0xffff)
										DVDD_EN_LOW;
									else 
										DVDD_EN_HIGH;
									delay_ms(2);
									VCI_EN_HIGH;
									delay_ms(100);		
									if((USB_Rx_Buffer[22]&0xfe) != 0xfe)
									{
										RDAC = AD_Value1[(USB_Rx_Buffer[22]&0x0e)>>1];
										RDAC_VDDIO = AD_Value2[(USB_Rx_Buffer[22]&0xc0)>>6];
										RDAC_DVDD = AD_Value3[(USB_Rx_Buffer[22]&0x30)>>4];
										
										VDD_AD5274_5271_Init(RDAC);
										VDDIO_AD5274_5271_Init(RDAC_VDDIO);
										DVDD_AD5274_5271_Init(RDAC_DVDD);				
									}		
								}	
								Power_ON_Flag=false;	
								FPGA_ResetProcess();
								Load_done_LOW;
								//OTP_POWER_Init(0.0,OTP_Disable);	//vpp off			
								//配置ICS307时钟芯片
								ICS307_Valid_Data = (u32)(USB_Rx_Buffer[16]<<24)|(u32)(USB_Rx_Buffer[15]<<16)|(u32)(USB_Rx_Buffer[14]<<8)|(u32)(USB_Rx_Buffer[13]);
								OLED.DisMode = ((USB_Rx_Buffer[18]&0x0f)<=2) ? 0 : 1;
								OLED.RGBMode = USB_Rx_Buffer[18]&0x0f;
								OLED.H_pixel = (OLED.DisMode == 0) ? (u16)(USB_Rx_Buffer[3]<<8)|(USB_Rx_Buffer[4]) : 2*((u16)(USB_Rx_Buffer[3]<<8)|(USB_Rx_Buffer[4]));
								OLED.V_pixel =  (u16)(USB_Rx_Buffer[8]<<8)|(USB_Rx_Buffer[9]);
								OLED.pixel_clk = (float)((((u16)(USB_Rx_Buffer[21]<<8)+USB_Rx_Buffer[20]))/10.0);
								ICS307_ValidClk_Set(ICS307_Valid_Data);   
								OLED.PHYMode = USB_Rx_Buffer[22]&0x01;
								

								if((USB_Rx_Buffer[18]&0XF0) < 0x20)
								{
									OLED.SigMode = USB_Rx_Buffer[18]&0XF0;
								}
								else if((USB_Rx_Buffer[18]&0XF0) >= 0x20)
								{
									switch((USB_Rx_Buffer[18]&0XF0))
									{
										case 	0x20:
										{
											OLED.SigMode = 0x20;
											DUAL_SPI_MODE = 0x00;
										}break;
										case	0x30:
										{
											OLED.SigMode = 0x20;
											DUAL_SPI_MODE = 0x01;
										}break;
										case	0x40:
										{
											OLED.SigMode = 0x20;
											DUAL_SPI_MODE = 0x02;
										}break;
										case	0x50:
										{
											OLED.SigMode = 0x30;
											DUAL_SPI_MODE = 0x03;
										}break;
										case	0x60:
										{
											OLED.SigMode = 0x30;
											DUAL_SPI_MODE = 0x04;
										}break;
										case	0x70:
										{
											OLED.SigMode = 0x30;
											DUAL_SPI_MODE = 0x05;
										}break;
										case	0x80:
										{
											OLED.SigMode = QuadSPI_Mode;
										  OuadSPI_Init();                //初始化QuadSPI IO
										}break;
									}
								}		
																		
								if((OLED.SigMode == Video_Mode)||(OLED.SigMode == CMD_Mode))
								{
										write_cmd(0x1234);	delay_us(4);					//将OLED时序数据发送到FPGA
										write_cmd((u16)(USB_Rx_Buffer[4]<<8)|(USB_Rx_Buffer[3]) );	delay_us(4);
										write_cmd((u16)(USB_Rx_Buffer[9]<<8)|(USB_Rx_Buffer[8]) );  delay_us(4);                              
										write_cmd((u16)(USB_Rx_Buffer[6]<<8) ) ;   delay_us(4);                            
										write_cmd((u16)(USB_Rx_Buffer[11]<<8) ) ;	 delay_us(4);
										write_cmd((u16)(USB_Rx_Buffer[5]<<8) ) ;	 delay_us(4);
										write_cmd((u16)(USB_Rx_Buffer[10]<<8 ) );	 delay_us(4);
										write_cmd((u16)(USB_Rx_Buffer[7]<<8) ) ;	 delay_us(4);
										write_cmd((u16)(USB_Rx_Buffer[12]<<8) ) ;	 delay_us(4);                                     
										write_cmd((u16)(USB_Rx_Buffer[18]<<8) + ((OLED.SigMode == Video_Mode) ? 0x00 : 0x01 )) ;	delay_us(4);
										write_cmd((u16)(USB_Rx_Buffer[17]));	delay_us(4);
										write_cmd(0x4321); delay_us(4);
								}                        
								if(OLED.DisMode!= 0)
										CS_Master = CS1_2;
								else
										CS_Master = CS1;
								CS_Slaver = CS2;                               
								SSD28xxCode_count = 0;
								SSD28xx_SCM_Code_count=0;
								InitCode_count = 0;
								VPP_POWER_Init(0.0,OTP_Disable);	
								Set_2828_reset(OLED.SigMode);        //复位2828
								if(OLED.SigMode==QuadSPI_Mode)
								{
								 FPGA_RESET_LOW;			//FPGA复位
								 SSD_RESET_LOW;			//SSD2832 RESET
								 qflag=1;
								}
								STM2PC_ERROR(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,0);          //返回 写LCD_Config状态  ：ok             
							}
							else if(REC_LCDCONF_CONVERT == Uart_rx_flag)		//上位机 发送 LCDConfig 数据
							{
								FPGA_RESET_LOW;			//FPGA复位
								delay_ms(30);
								FPGA_RESET_HIGH;
								delay_ms(100);		
								VPP_POWER_Init(0.0,OTP_Disable);	//vpp off						
							//配置ICS307时钟芯片
								ICS307_Valid_Data = (u32)(USB_Rx_Buffer[16]<<24)|(u32)(USB_Rx_Buffer[15]<<16)|(u32)(USB_Rx_Buffer[14]<<8)|(u32)(USB_Rx_Buffer[13]);
								OLED.DisMode = ((USB_Rx_Buffer[18]&0x0f)<=2) ? 0 : 1;
								OLED.RGBMode = USB_Rx_Buffer[18]&0x0f;
								OLED.H_pixel = (OLED.DisMode == 0) ? (u16)(USB_Rx_Buffer[3]<<8)|(USB_Rx_Buffer[4]) : 2*((u16)(USB_Rx_Buffer[3]<<8)|(USB_Rx_Buffer[4]));
								OLED.V_pixel =  (u16)(USB_Rx_Buffer[8]<<8)|(USB_Rx_Buffer[9]);
								OLED.pixel_clk = (float)((((u16)(USB_Rx_Buffer[21]<<8)+USB_Rx_Buffer[20]))/10.0);
								OLED.PHYMode = USB_Rx_Buffer[22]&0x01;
								if(Power_ON_Flag==false)
								{							
									if((USB_Rx_Buffer[22]&0xfe) != 0xfe)
									{
										RDAC = AD_Value1[(USB_Rx_Buffer[22]&0x0e)>>1];
										RDAC_VDDIO = AD_Value2[(USB_Rx_Buffer[22]&0xc0)>>6];
										RDAC_DVDD = AD_Value3[(USB_Rx_Buffer[22]&0x30)>>4];
										VDD_AD5274_5271_Init(RDAC);
										VDDIO_AD5274_5271_Init(RDAC_VDDIO);
										if(RDAC_DVDD == 0xffff)
										{
											DVDD_EN_LOW;
										}
										else 
										{
											DVDD_EN_HIGH;
											DVDD_AD5274_5271_Init(RDAC_DVDD);
										}			
									}
								}
								Power_ON_Flag=false;
								ICS307_ValidClk_Set(ICS307_Valid_Data);                        
								if((USB_Rx_Buffer[18]&0XF0) < 0x20)
								{
									OLED.SigMode = USB_Rx_Buffer[18]&0XF0;
								}
								else if((USB_Rx_Buffer[18]&0XF0) >= 0x20)
								{
									switch((USB_Rx_Buffer[18]&0XF0))
									{
										case 	0x20:
										{
											OLED.SigMode = 0x20;
											DUAL_SPI_MODE = 0x00;
										}break;
										case	0x30:
										{
											OLED.SigMode = 0x20;
											DUAL_SPI_MODE = 0x01;
										}break;
										case	0x40:
										{
											OLED.SigMode = 0x20;
											DUAL_SPI_MODE = 0x02;
										}break;
										case	0x50:
										{
											OLED.SigMode = 0x30;
											DUAL_SPI_MODE = 0x03;
										}break;
										case	0x60:
										{
											OLED.SigMode = 0x30;
											DUAL_SPI_MODE = 0x04;
										}break;
										case	0x70:
										{
											OLED.SigMode = 0x30;
											DUAL_SPI_MODE = 0x05;
										}break;
								
									}
								}
								if(OLED.SigMode == CMD_Mode||OLED.SigMode == Video_Mode)
								{
									write_cmd(0x1234);						//将OLED时序数据发送到FPGA
									write_cmd((u16)(USB_Rx_Buffer[4]<<8)|(USB_Rx_Buffer[3]) );	
									write_cmd((u16)(USB_Rx_Buffer[9]<<8)|(USB_Rx_Buffer[8]) );                                
									write_cmd((u16)(USB_Rx_Buffer[6]<<8) ) ;                               
									write_cmd((u16)(USB_Rx_Buffer[11]<<8) ) ;	
									write_cmd((u16)(USB_Rx_Buffer[5]<<8) ) ;	
									write_cmd((u16)(USB_Rx_Buffer[10]<<8 ) );	
									write_cmd((u16)(USB_Rx_Buffer[7]<<8) ) ;	
									write_cmd((u16)(USB_Rx_Buffer[12]<<8) ) ;	                                      
									write_cmd((u16)(USB_Rx_Buffer[18]<<8) + ((OLED.SigMode == Video_Mode) ? 0x00 : 0x01 )) ;	
									write_cmd((u16)(USB_Rx_Buffer[17]));	
									write_cmd(0x4321); 
									CS_Master = CS1_2;	
							
									FSMC_Pure_colour(0x000000);
									Load_done_HIGH;	
									SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,HS_B7_Data);	
									delay_ms(5);
									FSMC_Pure_colour(0x000000);
									//	Valid_BMP_No--;
									//	if (Valid_BMP_No==255)	Valid_BMP_No=PicShowedNum;
									//	FSMC_BMP_NUM(Valid_BMP_No);                     //当前画面序号												
									//当前画面序号
								}
								else
								{
									Load_done_LOW;	
									SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,LP_B7_Data);	
								}
								STM2PC_ERROR(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,0);           //返回 写LCD_Config状态  ：ok   				
							}							        
							/*         
							else if(REC_R_LCDCONF_FLAG == Uart_rx_flag)	//上位机 读取 LCDConfig 数据
							{										
								i = 0;
								WriteAddress = Inter_Flash_Addr;
								FLASH_If_Read(&WriteAddress, buffer1, 0,2048);	//将FLASH的模组Timing数据读取出来，准备发送给FPGA
								for(i=0;i<16;i++)
								{
										USB_Rx_Buffer[i*4]     = (u8)(buffer1[i]>>24);
										USB_Rx_Buffer[(i*4)+1] = (u8)(buffer1[i]>>16);
										USB_Rx_Buffer[(i*4)+2] = (u8)(buffer1[i]>>8);
										USB_Rx_Buffer[(i*4)+3] = (u8)(buffer1[i]);
								}									
								if((USB_Rx_Buffer[0] == 0x47)&&(USB_Rx_Buffer[1] == 0x56)&&(USB_Rx_Buffer[2] == 0x4F)&&(USB_Rx_Buffer[3] == 0x43)&&(USB_Rx_Buffer[4] == 0x6F)&&(USB_Rx_Buffer[5] == 0x6E))
									STM2PC_LCDConfig(pdev,CDC_IN_EP,Uart_rx_flag,USB_Rx_Buffer,Uart_Error_None);       //返回 读LCD_Config状态 ：ok；将LCD_Config数据返回
								else
									STM2PC_LCDConfig(pdev,CDC_IN_EP,Uart_rx_flag,USB_Rx_Buffer,Uart_Error_IntFlash);	//返回 flash内部没有配置文件 ：error									
						
							}
							*/	
							else if(REC_LCDCONF_POWER_ON == Uart_rx_flag)
							{	
								VDDIO_EN_HIGH;	
								delay_ms(2);
								if(USB_Rx_Buffer[5] == 0)
									DVDD_EN_LOW;
								else 
									DVDD_EN_HIGH;
								delay_ms(2);
								VCI_EN_HIGH;
								delay_ms(100);
								
								VCIc=(double)(USB_Rx_Buffer[3])/60;
								VDDIOc=(double)(USB_Rx_Buffer[4])/60;
								DVDDc=(double)(USB_Rx_Buffer[5])/60;
								
								RDAC = (double)((1544-440.1*VCIc))/(VCIc-1.816)-1;
								RDAC_VDDIO = (double)((978.6-415.8*VDDIOc))/(VDDIOc-1.197)-1;
								RDAC_DVDD = (double)((352.7-173.5*DVDDc))/(DVDDc-0.798)-1;
								
								VDD_AD5274_5271_Init(RDAC);
								VDDIO_AD5274_5271_Init(RDAC_VDDIO);
								DVDD_AD5274_5271_Init(RDAC_DVDD);
								Power_ON_Flag=true;
							}							
							else if((REC_W_PATTERN_FLAG == Uart_rx_flag)||(REC_W_RARTIAL_PATTERN_FLAG == Uart_rx_flag))	//上位机 发送 画面颜色 数据
							{	
								if(OLED.SigMode == Video_Mode)
								{    
									STM2PC_ERROR(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,0);								
									#if DSI_Set_Window_EN == 1
									SSD2832_Set_Window(OLED.SigMode,CS_Master,(OLED.H_pixel==390) ? 4 : 0,(OLED.H_pixel==390) ? OLED.H_pixel+4 : OLED.H_pixel,0,OLED.V_pixel);
									#endif                                
									if(REC_W_PATTERN_FLAG == Uart_rx_flag)
									{
										FSMC_Pure_colour((u32)(USB_Rx_Buffer[3]<<16)|((u32)(USB_Rx_Buffer[4]<<8)|USB_Rx_Buffer[5]));
										delay_ms(2);
										FSMC_Pure_colour((u32)(USB_Rx_Buffer[3]<<16)|((u32)(USB_Rx_Buffer[4]<<8)|USB_Rx_Buffer[5]));
										delay_ms(5);
										FSMC_Pure_colour((u32)(USB_Rx_Buffer[3]<<16)|((u32)(USB_Rx_Buffer[4]<<8)|USB_Rx_Buffer[5]));
									}
									else //IF REC_W_RARTIAL_PATTERN_FLAG
									{
										FSMC_Pure_Pic((0x4<<0x08)|USB_Rx_Buffer[6]);
									}
									Load_done_HIGH;
									SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,HS_B7_Data);
									PatternR = USB_Rx_Buffer[3];
									PatternG = USB_Rx_Buffer[4];
									PatternB = USB_Rx_Buffer[5]; 
								}
								else if(OLED.SigMode == CMD_Mode)            //Command 模式
								{
									#if DSI_Set_Window_EN == 1                    
									SSD2832_Set_Window(OLED.SigMode,CS_Master,(OLED.H_pixel==390) ? 4 : 0,(OLED.H_pixel==390) ? OLED.H_pixel+4 : OLED.H_pixel,0,OLED.V_pixel);
									#endif

									SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,HS_B7_Data);
									delay_ms(5); //chenfeng
									if(REC_W_RARTIAL_PATTERN_FLAG == Uart_rx_flag) //IF REC_W_RARTIAL_PATTERN_FLAG
									{
										FSMC_Pure_Pic((0x4<<0x08)|USB_Rx_Buffer[6]);
									}
									else
									{
										SSD2828_W_RAM_Pic(OLED.pixel_clk,OLED.SigMode,CS_Master,OLED.H_pixel,OLED.V_pixel,USB_Rx_Buffer[3],USB_Rx_Buffer[4],USB_Rx_Buffer[5]);  
									}
									SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,LP_B7_Data);	
									delay_ms(5);	
								}
								else if((OLED.SigMode == SPI3_Mode)||(OLED.SigMode == SPI4_Mode))          //3?8bit SPI ??   //4?8bit SPI ??
								{
									#if SPI_Set_Window_EN == 1                                 
								//    SPI_Set_Window(OLED.SigMode,CS_Master,0, OLED.H_pixel-1,0, OLED.V_pixel-1);
									#endif
									SPI3_PANEL_WriteRAM(OLED.SigMode,CS_Master,OLED.H_pixel,OLED.V_pixel,USB_Rx_Buffer[3],USB_Rx_Buffer[4],USB_Rx_Buffer[5],DUAL_SPI_MODE,OLED.RGBMode);
								}
								else if(OLED.SigMode == QuadSPI_Mode)          //QuadSPI_Mode
								{
							   OSPI_Write_GRAM_A1D4(OLED.SigMode,CS_Master,OLED.H_pixel,OLED.V_pixel,USB_Rx_Buffer[3],USB_Rx_Buffer[4],USB_Rx_Buffer[5],DUAL_SPI_MODE,OLED.RGBMode);
								}

							}
							else if(REC_R_PATTERN_FLAG == Uart_rx_flag)	//上位机 读取 画面颜色 数据
							{		
								STM2PC_Pattern(pdev,CDC_IN_EP,USB_Rx_Buffer[0],PatternR,PatternG,PatternB,Uart_Error_None);
							}
							else if(Uart_rx_flag == PrevPic)	//显示上一幅图片
							{		
								Valid_BMP_No--;
								if (Valid_BMP_No>24)	
								{
									Valid_BMP_No=PicShowedNum;
								}
								FSMC_BMP_NUM(Valid_BMP_No);                    //当前画面序号
								STM2PC_ERROR(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,Valid_BMP_No); 
							}
							else if(Uart_rx_flag == NextPic)	//显示下一幅图片
							{		
								Valid_BMP_No++;
								if (Valid_BMP_No>PicShowedNum)	
								{
									Valid_BMP_No=0;
								}
								FSMC_BMP_NUM(Valid_BMP_No); 
								STM2PC_ERROR(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,Valid_BMP_No); 
								//*pdev,uint8_t  ep_addr,   u8 State,        u8 CMD, u8 ERROR_CODE,u8 Other_data)
							}
							else if(REC_R_SW_VERSION_FLAG == Uart_rx_flag)	//上位机 读取 SW 版本号
							{
								if((USB_Rx_Buffer[3] == FW_Version)&&(USB_Rx_Buffer[4] == FW_SubVersion))
									STM2PC_SW_Version(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,FW_Version, FW_SubVersion,Device_ID);
								else 
								{
									STM2PC_SW_Version(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_Oth,FW_Version, FW_SubVersion,Device_ID);
									if((USB_Rx_Buffer[3] == 0)&&(USB_Rx_Buffer[4] == 0))
									{
										while(1)
										{
											delay_ms(500);
											LED_LOW;
											LED2_HIGH;
											delay_ms(500);
											LED2_LOW;
											LED_HIGH;
										}
									}
								}
							}
							else if(REC_W_DeviceID_FLAG == Uart_rx_flag)	//上位机 写入ID
							{
								Device_ID_Buf[0] = (USB_Rx_Buffer[3]!=0) ? (u32)(USB_Rx_Buffer[3]-0x30)*10+ (u32)(USB_Rx_Buffer[4]-0x30) : (u32)(USB_Rx_Buffer[4]-0x30);
								Device_ID = Device_ID_Buf[0];
								HAL_FLASH_Unlock();		//芯片内部FLASH每次操作都需要解锁
			//                            if(Device_Addr == Device_Flash_Addr + 0x10000)
			//                            {
			//                                Device_Addr = Device_Flash_Addr;
			//                                FLASH_EraseSector(Device_Flash_Sect, VoltageRange_3);
			//                            }
								FLASH_If_Write(Device_Addr, Device_ID_Buf, 1);
								HAL_FLASH_Lock();		//FLASH操作结束，锁上 
								STM2PC_ERROR(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,0);
							}
							else if(REC_W_DISP_WINDOW_CONF_FLAG == Uart_rx_flag) //??? ?? ??????
							{
								OLED_X0=(USB_Rx_Buffer[3]<<8)|(USB_Rx_Buffer[4]);
								OLED_X1=(USB_Rx_Buffer[5]<<8)|(USB_Rx_Buffer[6]);
								OLED_Y0=(USB_Rx_Buffer[7]<<8)|(USB_Rx_Buffer[8]);
								OLED_Y1=(USB_Rx_Buffer[9]<<8)|(USB_Rx_Buffer[10]);
								OLED_X_VALUE=OLED_X1-OLED_X0;
								OLED_Y_VALUE=OLED_Y1-OLED_Y0;
								
								OLED.H_pixel = (OLED.DisMode == 0) ? OLED_X_VALUE : 2*OLED_X_VALUE;
								OLED.V_pixel =  OLED_Y_VALUE;
								SSD2828_Set_Window(OLED.SigMode ,CS_Master,OLED_X0,OLED_X1,OLED_Y0,OLED_Y1);
															
								STM2PC_ERROR(pdev,CDC_IN_EP,USB_Rx_Buffer[0],Uart_rx_flag,Uart_Error_None,0);           //?? ?LCD_Config??  :ok   														
							}
						}
					}                                                                      
				}
				else if ((USB_Rx_Buffer[0]==BMP_FLAG)&&(USB_Rx_Buffer[1]==0x5a)&&(USB_Rx_Buffer[2]==0xa5)&&(USB_Rx_Buffer[3]==0x9d)&&(USB_Rx_Buffer[4]==0xf0))
				{//设定常规刷图 标志位，以及送图前的初始化设定
					FPGA_Fifo0Reset_LOW;
					BMP_START_FLAG=1;
					FPGA_Fifo0Reset_HIGH;
					if(OLED.SigMode == Video_Mode)  //RGB+SPI= MIPI
					{
						#if DSI_Set_Window_EN == 1                    
							SSD2828_Set_Window(OLED.SigMode,CS_Master,(OLED.H_pixel==390) ? 4 : 0,(OLED.H_pixel==390) ? OLED.H_pixel+4 : OLED.H_pixel,0,OLED.V_pixel);
						#endif                   
						if(Valid_BMP_No==25)
						{					
							Valid_BMP_No=0;
						}
						else
						{
							Valid_BMP_No++;
							if(PicShowedNum<25) PicShowedNum++;
						}
						write_cmd(0x3456); //将OLED时序数据发送到FPGA
						delay_us(4);
						write_cmd((u16)(((Valid_BMP_No*OLED.V_pixel*OLED.H_pixel)*8/5)>>16));				//	0:H_PIXEL	1:H_B	2:H_F	3:H_S	4:高8(单双6,8)
						delay_us(4);
						write_cmd((u16)((Valid_BMP_No*OLED.V_pixel*OLED.H_pixel)*8/5));						//	0:V_PIXEL	1:V_B	2:V_F	3:V_S	4:无效
						delay_us(4);
						write_cmd(0x6543);
						delay_us(4);
					}
					else if(OLED.SigMode == CMD_Mode)  //Command
					{             
						SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,HS_B7_Data);			//2020/11/17
						delay_ms(5);
						#if DSI_Set_Window_EN == 1                    
						SSD2828_Set_Window(OLED.SigMode,CS_Master,(OLED.H_pixel==390) ? 4 : 0,(OLED.H_pixel==390) ? OLED.H_pixel+4 : OLED.H_pixel,0,OLED.V_pixel);
						#endif
						SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBC,(u16) (OLED.H_pixel*OLED.V_pixel*3)); 
						SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBD,(u16)((OLED.H_pixel*OLED.V_pixel*3)>>16)); 

						if(OLED.H_pixel == 450)//2020.12.23 临时补丁： 6.8" VESA 10bit ，BEh设定值Hactive 450未能被12整除，设480则正常。
						{
							SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBE,(u16)(480));
						}
						else if(OLED.H_pixel*3<=4095)
						{
							SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBE,(u16)(OLED.H_pixel*3));//(OLED.H_pixel*3)); 
						}			
						else
						{
							SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBE,(u16)(OLED.H_pixel*3/2)); 
						}
						SSD2828_W_Cmd(OLED.SigMode,CS_Master,0xBF);
						SSD2828_W_Cmd(OLED.SigMode,CS_Master,0X2C);
					}
					else if((OLED.SigMode == SPI3_Mode)||(OLED.SigMode == SPI4_Mode))          //3线8bit SPI 模式   //4线8bit SPI 模式
					{
						#if SPI_Set_Window_EN == 1
						//		SPI_Set_Window  (OLED.SigMode,CS_Master,0, OLED.H_pixel-1,0, OLED.V_pixel-1);
						#endif
						//     SPI_Write_code  (OLED.SigMode,CS_Master ,0xFE,0x01);
						//     SPI_Write_code  (OLED.SigMode,CS_Master ,0x04,0x80);
						//     SPI_Write_code  (OLED.SigMode,CS_Master ,0xFE,0x00);
						//     SPI_Write_code  (OLED.SigMode,CS_Master ,0xC4,0x31);        // SPI3-SP3T 2Wire
					}		
	
					else if(OLED.SigMode ==QuadSPI_Mode)          //QuadSPI
					{
						BMP_START_FLAG=2;//jump to 新版快速刷图
						Rec_first_line_Flag =1;
					}
				}							
				else if ((USB_Rx_Buffer[0]==BMP_FLAG)&&(USB_Rx_Buffer[1]==0xa5)&&(USB_Rx_Buffer[2]==0x5a)&&(USB_Rx_Buffer[3]==0x9d)&&(USB_Rx_Buffer[4]==0xf0))
				{//设定新版 bmp 快速 刷图 标志位，以及送图前的初始化设定
					FPGA_Fifo0Reset_LOW;
					FPGA_Fifo0Reset_HIGH;
					BMP_START_FLAG=2; //新格式传输，速度更快
					if(OLED.SigMode == Video_Mode)  //RGB+SPI= MIPI
					{
							#if DSI_Set_Window_EN == 1                    
								SSD2828_Set_Window(OLED.SigMode,CS_Master,(OLED.H_pixel==390) ? 4 : 0,(OLED.H_pixel==390) ? OLED.H_pixel+4 : OLED.H_pixel,0,OLED.V_pixel);
							#endif                   
							if(Valid_BMP_No==25)
							{
								Valid_BMP_No=0;
							}
							else
							{
								Valid_BMP_No++;
								if(PicShowedNum<25) PicShowedNum++;
							}
							write_cmd(0x3456); //将OLED时序数据发送到FPGA
							delay_us(1);
							write_cmd((u16)(((Valid_BMP_No*OLED.V_pixel*OLED.H_pixel)*8/5)>>16));				//	0:H_PIXEL	1:H_B	2:H_F	3:H_S	4:高8(单双6,8)
							delay_us(1);
							write_cmd((u16)((Valid_BMP_No*OLED.V_pixel*OLED.H_pixel)*8/5));						//	0:V_PIXEL	1:V_B	2:V_F	3:V_S	4:无效
							delay_us(1);
							write_cmd(0x6543);
							delay_us(1);
					}
					else if(OLED.SigMode == CMD_Mode)  //Command
					{             
						SSD2828_W_Reg(OLED.SigMode,CS_Master,0xB7,HS_B7_Data);			//2020/11/17
						delay_ms(5);
						#if DSI_Set_Window_EN == 1                    
						SSD2828_Set_Window(OLED.SigMode,CS_Master,(OLED.H_pixel==390) ? 4 : 0,(OLED.H_pixel==390) ? OLED.H_pixel+4 : OLED.H_pixel,0,OLED.V_pixel);
						#endif
						SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBC,(u16) (OLED.H_pixel*OLED.V_pixel*3)); 
						SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBD,(u16)((OLED.H_pixel*OLED.V_pixel*3)>>16)); 

						if(OLED.H_pixel == 450)//2020.12.23 临时补丁： 6.8" VESA 10bit ，BEh设定值Hactive 450未能被12整除，设480则正常。
						{
							SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBE,(u16)(480));
						}
						else if(OLED.H_pixel*3<=4095)
						{
							SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBE,(u16)(OLED.H_pixel*3));//(OLED.H_pixel*3)); 
						}			
						else
						{
							SSD2828_W_Reg(OLED.SigMode,CS_Master,0xBE,(u16)(OLED.H_pixel*3/2)); 
						}
						SSD2828_W_Cmd(OLED.SigMode,CS_Master,0xBF);
						SSD2828_W_Cmd(OLED.SigMode,CS_Master,0X2C);
					}
					else if((OLED.SigMode == SPI3_Mode)||(OLED.SigMode == SPI4_Mode))          //3线8bit SPI 模式   //4线8bit SPI 模式
					{
						#if SPI_Set_Window_EN == 1
					//	SPI_Set_Window  (OLED.SigMode,CS_Master,0, OLED.H_pixel-1,0, OLED.V_pixel-1);
						#endif
			//					SPI_Write_code  (OLED.SigMode,CS_Master ,0xFE,0x01);
			//					SPI_Write_code  (OLED.SigMode,CS_Master ,0x04,0x80);
			//					SPI_Write_code  (OLED.SigMode,CS_Master ,0xFE,0x00);
			//					SPI_Write_code  (OLED.SigMode,CS_Master ,0xC4,0x31);        // SPI3-SP3T 2Wire
					}
					else if(OLED.SigMode ==QuadSPI_Mode)          //QuadSPI
					{
             BMP_START_FLAG=2;//jump to 新版快速刷图
					}
				}
				else if ((USB_ReceivedCount==9)&&(USB_Rx_Buffer[0]==BMP_FLAG)&&(USB_Rx_Buffer[1]==0x5b)&&(USB_Rx_Buffer[2]==0xb5)&&(USB_Rx_Buffer[3]==0xd9)&&(USB_Rx_Buffer[4]==0x9d))
				{
					Demura_START_FLAG=1; //供HFZ部分窗体的Demura流程使用
					USB_Rx_Demura=0;
					USB_Rx_Demura_Total_Num=(USB_Rx_Buffer[5]<<24)+(USB_Rx_Buffer[6]<<16)+(USB_Rx_Buffer[7]<<8)+USB_Rx_Buffer[8];
				}
				else if ((USB_ReceivedCount==11)&&(USB_Rx_Buffer[2]==BMP_FLAG)&&(USB_Rx_Buffer[3]==0xcf)&&(USB_Rx_Buffer[4]==0xfc)&&(USB_Rx_Buffer[5]==0xac)&&(USB_Rx_Buffer[6]==0xca))
				{	//Demura官方推荐流程，对同一种IC的不同产品型号做区分
					Demura_START_FLAG=2; //Demura官方推荐流程，对同一种IC的不同产品型号做区分
					USB_Rx_Demura=0;
					DemuraIctype=USB_Rx_Buffer[0]; //获取IC型号		
					Demura_OLEDModule_flag=USB_Rx_Buffer[1]	; //获取产品型号			
					USB_Rx_Demura_Total_Num=(USB_Rx_Buffer[7]<<24)+(USB_Rx_Buffer[8]<<16)+(USB_Rx_Buffer[9]<<8)+USB_Rx_Buffer[10];
				}
				else if((((USB_Rx_Buffer[0]==REC_SSD_CODE_START)&&(USB_Rx_Demura==0)&&(NUM==0)&&(BMP_START_FLAG==0))||(Receive_Code_flag == 1))&&(Receive_BIN_Flag == 0)) //接受的数据长度非固定
				{	//SSD282/2832 DDIC 模组显示初始化
/*					
					VDDIO_EN_HIGH;	
					delay_ms(2);
					if(RDAC_DVDD == 0xffff)
						DVDD_EN_LOW;
					else 
						DVDD_EN_HIGH;
					delay_ms(2);
					VCI_EN_HIGH;
					delay_ms(100);*/
					//delay_ms(150);
					//////////////////////20210114 上电时序控制后续添加
					if(Receive_Code_flag == 0)
					{
						Receive_Code_flag = 1;
						Uart_rx_flag=USB_Rx_Buffer[1]&0x0f;
					}
					for(i=0;i<USB_ReceivedCount;i++)
					{
						buffer[i+VCP_Receive_True_num] = USB_Rx_Buffer[i];
					}		
					VCP_Receive_True_num+=USB_ReceivedCount;
					if(VCP_Receive_True_num==(buffer[1]>>4)*256+buffer[2]+5)
					{
						Receive_Code_flag = 0;
						if((REC_W_SSD_ONE_FLAG == Uart_rx_flag)||(REC_W_SSD_FLAG == Uart_rx_flag)||(REC_W_SSD_SCM_FLAG == Uart_rx_flag)||(REC_W_SSD_SCM_ONE_FLAG == Uart_rx_flag))		//上位机  发送 SSD2828 命令
						{
							SSD28xxCode_count = 0;
							SSD28xx_SCM_Code_count=0;
							STM2PC_ERROR(pdev,CDC_IN_EP,buffer[0],Uart_rx_flag,Uart_Error_None,0);
							if(REC_W_SSD_ONE_FLAG == Uart_rx_flag)  //单指令发送
							{										
								if(OLED.SigMode == Video_Mode)  //RGB+SPI= MIPI
								{      
									SSD2828_W_Reg(OLED.SigMode,CS_Master,buffer[3],(u16)(buffer[4]<<8)|buffer[5]);
								}
								else if(OLED.SigMode == CMD_Mode)//Command
								{
									SSD2828_W_Reg(OLED.SigMode,CS_Master,buffer[3],(u16)(buffer[4]<<8)|buffer[5]);                                 
								}
								if(buffer[3] == 0xB7)
								{
									if(((u16)(buffer[4]<<8)|buffer[5])&0x0001)
										HS_B7_Data = (u16)(buffer[4]<<8)|buffer[5];
									else
										LP_B7_Data = (u16)(buffer[4]<<8)|buffer[5];
								}                           
							}
							else if(REC_W_SSD_SCM_ONE_FLAG == Uart_rx_flag)  //单指令SCM发送
							{										
								SSD2828_W_SCM_Reg_u32(OLED.SigMode ,CS_Master, (u16)((buffer[3]<<8) + buffer[4]),(u32)((buffer[5]<<24) +(buffer[6]<<16)+(buffer[7]<<8)+buffer[8]));                
							}
							else if(REC_W_SSD_SCM_FLAG == Uart_rx_flag) //Send SCM Code
							{
								//userable data from bit[3]
								for (i = 0; i < 512; i++)		//将2828的配置数据 转换成字
								{
									if (buffer[i * 6 +3] == 0xff)
									{
										break;
									}
									//    0x H H H H = 0x H H H H H H H H :   31:24->00(没作用)   23:16->(没作用)    15:0->寄存器值(CMD MSB ; CMD LSB)
									SSD28xx_SCM_Cmd[SSD28xx_SCM_Code_count]=((uint32_t)buffer[i * 6 + 3]<<8) + ((uint32_t)buffer[i * 6 + 1 + 3]);
									//    0x H H H H = 0x H H H H H H H H :   31:24->data3   23:16->data2    15:0->寄存器值(data1 data0)
									SSD28xx_SCM_Data[SSD28xx_SCM_Code_count]=((uint32_t)buffer[i * 6 + 2 + 3]<<24)+((uint32_t)buffer[i * 6 + 3 + 3]<<16) + ((uint32_t)buffer[i * 6 + 4 + 3]<<8) + ((uint32_t)buffer[i * 6 + 5 + 3]);
									SSD28xx_SCM_Code_count++;
								}	
								SSD2832_initial_SCM(OLED.SigMode,CS_Master); //download 2832 SCM cfg
							}
							else //Send SSD Code
							{
								if((OLED.SigMode == Video_Mode)||(OLED.SigMode == CMD_Mode))
								{
									for (i = 0; i < 512; i++)		//将2828的配置数据 转换成字
									{
										if (buffer[i * 3 +3] == 0xff)
										{
											break;                    
										}
										//    0x H H H H  :   31:24->00(没作用)   23:16->寄存器地址    15:0->寄存器值(高位在前)
										SSD28xx_Code[SSD28xxCode_count] = ((uint32_t)buffer[i * 3 +3]<<16) + ((uint32_t)buffer[i * 3 + 1+3]<<8) + ((uint32_t)buffer[i * 3 + 2+3]);
										SSD28xxCode_count ++;	
										if(buffer[i * 3 +3] == 0xB7)
										{
											if(((u16)(buffer[i * 3 +4]<<8)|buffer[i * 3 +5])&0x0001)
											{
												HS_B7_Data = (u16)(buffer[i * 3 +4]<<8)|buffer[i * 3 +5];
											}
											else
											{	LP_B7_Data = (u16)(buffer[i * 3 +4]<<8)|buffer[i * 3 +5]; }                                        
										}
									}
									SSD2828_initial_on(OLED.SigMode,CS_Master); //download 2828 cfg
								}                                
							} 
						}
						else if((REC_W_CODE_ONE_FLAG == Uart_rx_flag)||(REC_W_CODE_FLAG == Uart_rx_flag))		//上位机  发送 DriverIC code
						{	
							InitCode_count = 0;
							//STM2PC_ERROR(pdev,CDC_IN_EP,buffer[0],Uart_rx_flag,Uart_Error_None,0);
							if(REC_W_CODE_ONE_FLAG == Uart_rx_flag)
							{
								if((OLED.SigMode == Video_Mode)||(OLED.SigMode == CMD_Mode))  //RGB+SPI= MIPI
								{									
									SSD2828_W_Array(OLED.SigMode,CS_Master,buffer,2);
								}
								else if((OLED.SigMode == SPI3_Mode)||(OLED.SigMode == SPI4_Mode))          //3线8bit SPI 模式   //4线8bit SPI 模式
								{
									temp_spi_num = buffer[2];
									for(i=0;i<temp_spi_num+1;i++)
									buffer[i] = buffer[i+2];
									if(buffer[0] > 1)
									{
										SPI_PANEL_Write_u8_Array(OLED.SigMode,CS_Master,buffer);
									}
									else if(buffer[0] == 1)
									{
										SPI_PANEL_Write_u8_Cmd(OLED.SigMode,CS_Master,buffer[1]);
										if(buffer[1] == 0x11){		delay_ms(120);	}
										delay_ms(1);
									}  
								}
							  else if(OLED.SigMode == QuadSPI_Mode)          //QuadSPI_Mode
								{
									temp_spi_num = buffer[2];
									for(i=0;i<temp_spi_num+1;i++)
									buffer[i] = buffer[i+2];
									if(buffer[0] > 1)
									{
										OSPI_Write_u8_Array(OLED.SigMode,CS_Master,buffer,0);
									}
									else if(buffer[0] == 1)
									{
										OSPI_Write_u8_Array(OLED.SigMode,CS_Master,buffer,0);
										if(buffer[1] == 0x11){		delay_ms(120);	}
										delay_ms(1);
									}  
								}
							}
							else
							{
								for (i = 3; i < 8192; i += (Code_length+1))
								{
									Code_length = buffer[i];	//每一句初始化代码的 数据长度

									if (Code_length == 0xff)	//判断长度有255说明 ，到初始化代码的最后
									{
										break;
									}
									Timing_and_InitCode[0] =	Code_length;	//数组中的[0]：这一句初始化代码的数据长度									
									for (j = 1; j < Code_length+1; j++)	//递增将 初始化代码写入到数组
									{											
										Timing_and_InitCode[j] = ((uint32_t)buffer[i+j]);
									}									
									for(j=0;j<Timing_and_InitCode[0]+1;j++)			//整合一行初始化全部内容									
									{	InitCode_valid[InitCode_count][j] = (u8)Timing_and_InitCode[j];	
									}								
									InitCode_count ++;	//即将写下一个数组(下一句初始化代码)
								}
								if((OLED.SigMode == Video_Mode)||(OLED.SigMode == CMD_Mode))  //RGB+SPI= MIPI
								{									
									//SSD2828_signal_on(OLED.SigMode,CS_Master);
									Driver_ic_initial_on(OLED.SigMode,CS_Master);
								}
								else if((OLED.SigMode == SPI3_Mode)||(OLED.SigMode == SPI4_Mode))          //3线8bit SPI 模式   //4线8bit SPI 模式
								{
									SPI_signal_on(OLED.SigMode,CS_Master);
								}
							}  
						}
						else if(REC_R_CODE_FLAG == Uart_rx_flag)		//上位机  读取 DriverIC code
						{
							//这部分功能放在通用读取模块，详情搜索关键字“GenWR”
						}    
						VCP_Receive_True_num = 0;
					}
					xx: delay_ms(1);
				}
				else if ((USB_Rx_Buffer[0]==REC_SSD_READ_START)&&(USB_Rx_Buffer[1]==0x05)&&(USB_ReceivedCount==0x0A))	//SSD2828/2832 寄存器回读	
				{	//SSD2828/2832 寄存器回读
					u32 tep;		
					if(USB_Rx_Buffer[2]==0x03)
					{	
						tep=SSD2828_R_Reg(Video_Mode,CS1,USB_Rx_Buffer[3]); //返回SSD2832 REG 值,一次读取32位
						USB_Rx_Buffer[4]=(u8)(tep>>24);
						USB_Rx_Buffer[5]=(u8)(tep>>16);
						USB_Rx_Buffer[6]=(u8)(tep>>8);
						USB_Rx_Buffer[7]=(u8)(tep);
						STM2PC_SSD2828(pdev,CDC_IN_EP,USB_Rx_Buffer,8);
					}		
				}										
				else if ((USB_Rx_Buffer[0]==PMU_MTR)&&(USB_Rx_Buffer[1]==0x05)&&(USB_ReceivedCount==0x26))//功耗测试
				{	//功耗测试
					if(USB_Rx_Buffer[3]==0x00)
					{
						u32 tep;
						u32 adc_ch1,adc_ch2;
						//返回VDD VDDIO AVDD ELVDD ELVSS 测量的电压 电流值
						buffer[0]=0x9e;
						buffer[1] = 0x05; //lock
						buffer[2] = 33; //length
						buffer[3] =0x00;	
						
						tep=Measure_IDD_once(DeviceAddr_ELVDD);						
						buffer[5]=(u8)(tep>>24);
						buffer[4]=(u8)(tep>>16);
						buffer[7]=(u8)(tep>>8);
						buffer[6]=(u8)(tep);
						delay_us(1);
						tep=Measure_IDD_once(DeviceAddr_AVDD);						
						buffer[9]=(u8)(tep>>24);
						buffer[8]=(u8)(tep>>16);
						buffer[11]=(u8)(tep>>8);
						buffer[10]=(u8)(tep);
						delay_us(1);
						tep=Measure_IDD_once(DeviceAddr_VCI);						
						buffer[13]=(u8)(tep>>24);
						buffer[12]=(u8)(tep>>16);
						buffer[15]=(u8)(tep>>8);
						buffer[14]=(u8)(tep);
						delay_us(1);
						tep=Measure_IDD_once(DeviceAddr_VDDIO);						
						buffer[17]=(u8)(tep>>24);
						buffer[16]=(u8)(tep>>16);
						buffer[19]=(u8)(tep>>8);
						buffer[18]=(u8)(tep);
						delay_us(1);	
						tep=Measure_IDD_once(DeviceAddr_VBAT);						
						buffer[21]=(u8)(tep>>24);
						buffer[20]=(u8)(tep>>16);
						buffer[23]=(u8)(tep>>8);
						buffer[22]=(u8)(tep);
						delay_us(1);		
						tep=Measure_IDD_once(DeviceAddr_DVDD);						
						buffer[25]=(u8)(tep>>24);
						buffer[24]=(u8)(tep>>16);
						buffer[27]=(u8)(tep>>8);
						buffer[26]=(u8)(tep);
						delay_us(1);		
						//adc_ch1=Get_Adc_Average(ADC_CHANNEL_1,20);//采样通道1，20次转换值取平均
						adc_ch2=Get_Adc_Average(ADC_CHANNEL_2,5);	//采样通道1，20次转换值取平均
						buffer[29]=(u8)(adc_ch2>>8);
						buffer[28]=(u8)(adc_ch2); //ELVSS电压
						delay_us(1);	
						/*	
						adc_ch1=Get_Adc_Average(ADC_CHANNEL_1,20);//采样通道1，20次转换值取平均
						buffPowerR[19]=(u8)(adc_ch1>>8);
						buffPowerR[20]=(u8)(adc_ch1); ////ELVSS 电流
						*/		
						STM2PC_SSD2828(pdev,CDC_IN_EP,buffer,buffer[2]+3);					
						
						//PMU_Oled_Measure(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
					}
					else if	(USB_Rx_Buffer[3]==0x01)
					{	
						PMU_Oled_Vci_Vddi_Trim(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
					}
					else if(USB_Rx_Buffer[3]==0x02)//切档
					{
						PMU_Oled_mAuA_Gear(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
					}
				}
				else if(((USB_ReceivedCount==USB_Rx_Buffer[2]+5)|(USB_ReceivedCount==TotalNum+6))   &&(USB_Rx_Demura==0)&&(NUM==0)&&(Receive_BIN_Flag == 0)&&(Receive_BIN_Flag1 == 0))   //数据长度 固定
				{	//--配置DDIC,处理初始化、OTP、Gamma等功能---	//如果此时数据长度和标志位记录不符，则认为传过来的是Demura数据(主要给瑞鼎IC用)
					Uart_rx_flag=USB_Rx_Buffer[1]&0x0f;	//?
								
					if (TotalNum>0)   //临时判断传过来的新旧指令表，只有新指令表时，TotalNum才大于零
					{	crc16_data1 = crc16(USB_Rx_Buffer,TotalNum+4,0xFFFF);
						if (crc16_data1 == ((USB_Rx_Buffer[TotalNum+4]<<8)|(USB_Rx_Buffer[TotalNum+5])))
							crc16_data1=1; //crc16_data1默认为0，crc16_data1=1意味着通过新协议传过来的数据是正确的
						else 
						{crc16_data1=0;	
						}
					}//其实如果此时传输中出现错误，则....TODO
					crc16_data = crc16(USB_Rx_Buffer,USB_Rx_Buffer[2]+3,0xFFFF);
					if(crc16_data1|(crc16_data == ((USB_Rx_Buffer[USB_Rx_Buffer[2]+3]<<8)|(USB_Rx_Buffer[USB_Rx_Buffer[2]+4]))))
					{
						switch (USB_Rx_Buffer[0])
						{
							case Rec_R_Config_Start:
							{
								if(Rec_R_Config_flag == Uart_rx_flag)		//上位机  读取  配置文件 命令
								{
									WriteAddress = Inter_Flash_Addr;
									SendTo_PC_cfgFile=1;
								}
								break;
							}
							case REC_UPDATABIN_Start:
							{
								Receive_BIN_Flag1 = 1;
								Receive_BIN_Length = (USB_Rx_Buffer[3]<<24)+(USB_Rx_Buffer[4]<<16)+(USB_Rx_Buffer[5]<<8)+USB_Rx_Buffer[6];
								USB_Rx_Buffer[4] = Uart_Error_None;
								STM2PC(pdev,CDC_IN_EP,USB_Rx_Buffer,USB_Rx_Buffer[2]+3);           //返回 写寄存器状态  ：ok 
								break;  
							}
							//---------------------------------Gamma Setting Start---------------------------------------------------------	
							case HX83200:
							{
								ProcessForIc2B(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
							}	break; 												
							case NT37710:
							{
								ProcessForIc2A(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break; 
							case ICN9608:
							{
								ProcessForIc2D(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break; 
							case CH13721:
							{
								ProcessForIc4A(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	  
							}	break; 
							case FT2711:
							{
								//ProcessForIc4B(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	 
							}	break; 
							case GenWR://通用读写
							{
								ProcessForIc99(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break; 						
							case UD61720:
							{
								ProcessForIc4C(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	  
							}	break; 															
							case RM67120:
							{
								ProcessForIc08(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	                                   
							}	break; 
							case RM67195:
							case RM67295:
							case RM67198:
							case RM67298:										
							{
								ProcessForIc2E(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	             
							}	break;	
							case RM67160:
							case RM67162:
							{
								ProcessForIc1E(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break; 
							case RM6D010:
							{
								ProcessForIc3D(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break; 
							case RM69300:
							{
								ProcessForIc2C(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	                   
							}	break; 
							case RM69350:
							{
								ProcessForIc3C(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break; 
							case R66455:
							{	
								ProcessForIc30(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);											
							}	break; 
							case TC1100:
							{	
								ProcessForIc31(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);												
							}	break; 
							case RM69330:
							{
								ProcessForIc32(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);//ADD BY PCS	
							}break;
							case HX83201A:
							{	
								ProcessForIc51(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);												
							}	break; 
							case VTDR6100:
							{	
								ProcessForIc4D(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);											
							}	break; 
							case RM69310:
							{
								ProcessForIc52(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
							}break;
							case FT2201:
							{
								ProcessForIc53(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}break;
							case RM692A9:
							{
								ProcessForIc3E(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);												
							}	break; 
							
							case NT37700C:
							{
								ProcessForIc4E(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);														
							}	break; 
							
							case RM692C4:   //#define RM692C4				0x3F
							{
								ProcessForIc3F(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
							}	break; 
							case RM692C9:	//#define RM692C9				0x4F  
							{
								ProcessForIc4F(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
							}	break;
							
							case 0x41:    //从这里开始添加新
							{
								ProcessForIc41(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
							}	break; 
							case 0x42:   
							{
								ProcessForIc42(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);												
							}	break; 
							//
							case ILI7835:     //0x56
							{
								ProcessForIc56(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);												
							}	break; 
							case ICNA3310:     //0x57
							{
								ProcessForIc57(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);												
							}	break; 
							case RM69091:     //0x58
							{
								ProcessForIc58(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);												
							}	break; 
							case RM690A0_GW910:   //0x61
							{
								ProcessForIc61(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;   
							case ILI8688:     //0x63
							{
								ProcessForIc63(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break; 
							case RM692EX:     //0x64
							{
								ProcessForIc64(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;					
							case SD5202: //0x65
							{	
								ProcessForIc65(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;	
							case RM69310_GW010: //0x67
							{
								ProcessForIc67(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							} break;
							case RM692D9:
							{
								ProcessForIc68(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);  
							}break;
							case NT37800A:
							{
								ProcessForIc69(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	  
							}break;
							case NT37701A:
							{
								ProcessForIc6A(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	 
							} break;
							case VTDR6110C:   //VTDR6110C_601
							{
								ProcessForIc6B(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	  
							}break;
							case SD5205: //0x6D
							{	
								ProcessForIc6D(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;	
							case ILI8818: //0x6F
							{	
								ProcessForIc6F(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;
							case VT6110C: //0x70
							{	
								ProcessForIc70(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;
							case CH13726: //0x71
							{	
								ProcessForIc71(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;
							case NT37350: //0x72
							{	
								ProcessForIc72(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;
							case NT37350_155: //0x73
							{	
								ProcessForIc73(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;
							
							case SD4202: //0x74
							{	
								ProcessForIc74(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;
							case NT37350M: //0x75
							{	
								ProcessForIc75(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
							}	break;							
							//---------------------------------Gamma Setting End---------------------------------------------------------				
							//---------------------------------Demura Setting Start------------------------------------------------------							
							case DE_MURA: //BYTE[0] 0x2F
							{
									switch(USB_Rx_Buffer[3]) //BYTE[3]
									{
										case 0x00: //GM820
										{
											ProcessForDmuR00(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 					
										case 0x01: //GM825
										{
											ProcessForDmuR01(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 	
										case 0x02: //GM830
										{
											ProcessForDmuR02(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 	
										case 0x03: //GM870
										{
											ProcessForDmuR03(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 							
										case 0x04: //RM69297&298&299
										{
											ProcessForDmuR04(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 		
										case 0x05: //GM760
										{
											ProcessForDmuR05(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 		
										case 0x06: //GM620
										{
											ProcessForDmuR06(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 		
										case 0x07: //GM820_NT37700C
										{
											ProcessForDmuR07(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 
										case 0x08: //GM870_VT5100
										{
											ProcessForDmuR08(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;									
										case 0x09: //GM8A0_RM692C9
										case 0x11: //Send_buf[3] = 0x11:692Ax-KPQ/641  ;0x13:692Cx---M2
										case 0x12: //6.088
										{
											ProcessForDmuR09(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;										
										case 0x0A: //
										{
											ProcessForDmuR0A(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;	
										case 0x0B: //GM8A0_RM69200
										{
											ProcessForDmuR0B(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;			
										case 0x0C: //GT666_RM692A9
										{
											ProcessForDmuR0C(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;	
										case 0x0D: //F4_RM692C4
										{
											ProcessForDmuR0D(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break; 
										case 0x0E: //R66451_ALPHA
										{
											ProcessForDmuR0E(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;	
										case 0x0F: //R66451_GM862
										{
											ProcessForDmuR0F(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;
										case 0x10:
										{
											ProcessForDmuR10(pdev,CDC_IN_EP,OLED.SigMode,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);										
										}break;
										case 0x13:  //R692c9_GM930
										{
											ProcessForDmuR13(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;	
										case 0x14:  //R69351_GM920
										{
											ProcessForDmuR14(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;		
										case 0x15:  //R692C9_GM828
										{
											ProcessForDmuR15(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;							
										case 0x18:  //R692C9_GM010
										{
											ProcessForDmuR18(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;	
										case 0x19: //0x19:692dx
										{
											ProcessForDmuR19(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;
										case 0x1A: //0x1A:692d7--6.44
										{
											ProcessForDmuR1A(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;									
										case 0x1B: //0x1B:NT37700A
										{
											ProcessForDmuR1B(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;		
										case 0x1C: //0x1C:NT37701A
										{
											ProcessForDmuR1C(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;	
										case 0x1D: //VTDR6110C 601
										{
											ProcessForDmuR1D(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;	
										case 0x1F:  //ILI7835_621
										{
											ProcessForDmuR1F(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);													
										}	break;
										case 0x20: //RM692EX    6.67  demura IP 2*4
										{
											ProcessForDmuR20_IP(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data,5);		
										}break;
										case 0x21: //NT37701_639DOE
										{
											ProcessForDmuR21(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}break;
										case 0x22: //RM692E1_667
										{
											ProcessForDmuR22(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}break;
										case 0x23: //RM692EX    6.67  demura IP 4*2
										{
											ProcessForDmuR20_IP(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data,6);		
										}break;
										case 0x24: //RM692EX    6.67 
										{
											ProcessForDmuR20_IP(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data,5);		
										}break;	
										case 0x25: //RM692D0_667                     //23 24被春辉占了，没用，怕怕
										{
											ProcessForDmuR25(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}break;
										case 0x26: //RM692C9_643                     
										{
											ProcessForDmuR26(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}break;		
										case 0x27: //NT37800A_680                     
										{
											ProcessForDmuR27(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}break;
										case 0x28: //RM692C9_GM060 662                     
										{
											ProcessForDmuR28(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}break;	
										case 0x29: //RM692C9_GM070 611  ////7838占用了     ProcessForDmuR29，被迫加后缀。            
										{
											ProcessForDmuR29A(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}break;	
										case 0x2A: //SD4202  644二供
										{
											ProcessForDmuR2A(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
										}break;
										case 0x2B:
										{
											ProcessForDmuR2B(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
										}break;
										case 0x2C:
										{
											ProcessForDmuR2C(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);	
										}break;
										case 0x2D:
										{
											ProcessForDmuR2D(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);		
										}	break;
										
										case 0x59: //SK622_RM69350
										{
											ProcessForDmuR59(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
										}break;               
									}								
							}	break; 
							//------------------------------------Demura Setting End-------------------------------------------------------------							
							case GenWRHFZ:	//#define GenWRHFZ            0x9F
							{
								switch (USB_Rx_Buffer[1]&0x80)
								{            
									case 0:                                      //写寄存器
										HFZGenerate_Write_Function(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);break;	
									case 0x80:                                     //读寄存器
										//HFZGenerate_Read_Function(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);break;	
									default:	break;	
								}
							}	break; 	
							case GenSTM32FSMC2FPGA:	//#define GenSTM32FSMC2FPGA            0x9D
							{
								switch (USB_Rx_Buffer[1]&0x80)
								{            
									case 0:                                      //写寄存器
										GenSTM32FSMC2FPGA_Write_Function(pdev,CDC_IN_EP,OLED.SigMode ,CS_Master,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);break;	
									case 0x80:                                     //读寄存器
										break;	
									default:	break;	
								}
							}	break; 	//GenSTM32FSMC2FPGA
							
							default:	break;						
						}
					}                 
				}
				else
				{   
					//BMP 显示               
					if((NUM==0)&&(Receive_BIN_Flag == 0)&&(Receive_BIN_Flag1 == 0))
					{ NUM = 1;Rec_first_line_Flag = 1;}
					if((NUM==1)&&(Receive_BIN_Flag == 0)&&(Receive_BIN_Flag == 0))
					{	//此处为旧版送图具体处理，因为速度较慢，后续不再维护，为兼容某些窗口暂时保留这部分
						for(i=0;i<USB_ReceivedCount;i++)
							buffer[i+VCP_Receive_True_num] = USB_Rx_Buffer[i];     
							VCP_Receive_True_num+=USB_ReceivedCount;
						if(VCP_Receive_True_num == OLED.H_pixel*3 || VCP_Receive_True_num == OLED.H_pixel*2) // OLED.H_pixel*3
						{  //此处为旧版送图具体处理，因为速度较慢，后续不再维护，为兼容某些窗口暂时保留这部分   
							if(OLED.SigMode == Video_Mode)  //RGB+SPI= MIPI
							{	//此处为旧版送图具体处理，因为速度较慢，后续不再维护，为兼容某些窗口暂时保留这部分
								SSD2828_W_RAM_buffer_8bits_part(OLED.pixel_clk,OLED.SigMode,buffer,OLED.H_pixel,1,OLED.DisMode);
							}
							else if(OLED.SigMode == CMD_Mode)  //Command
							{	//此处为旧版送图具体处理，因为速度较慢，后续不再维护，为兼容某些窗口暂时保留这部分
								SPI_CS_Select(CS_Master,0);
								SSD2828_W_RAM_buffer_8bits_part(OLED.pixel_clk,OLED.SigMode,buffer,OLED.H_pixel,1,0);
								SPI_CS_Select(CS_Master,1);
							}
							else if((OLED.SigMode == SPI3_Mode)||(OLED.SigMode == SPI4_Mode))          //3线8bit SPI 模式   //4线8bit SPI 模式
							{   //此处为旧版送图具体处理，因为速度较慢，后续不再维护，为兼容某些窗口暂时保留这部分 
								SPI_PANEL_WriteRAM_buffer_part(OLED.SigMode,CS_Master,buffer,OLED.H_pixel,1,Rec_first_line_Flag,DUAL_SPI_MODE,OLED.RGBMode);
								if(Rec_first_line_Flag == 1)
									Rec_first_line_Flag = 0;
							} 
							VCP_Receive_True_num=0;
						}	
					}
						
				}			        
			} 
			LED4_HIGH;	
		}
	}		
	return USBD_OK;
}

/**
  * @brief  USBD_CDC_EP0_RxReady
  *         Handle EP0 Rx Ready event
  * @param  pdev: device instance
  * @retval status
  */
static uint8_t  USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
{
  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

  if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
  {
    ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
                                                      (uint8_t *)(void *)hcdc->data,
                                                      (uint16_t)hcdc->CmdLength);
      hcdc->CmdOpCode = 0xFFU;

  }
  return USBD_OK;
}

/**
  * @brief  USBD_CDC_GetFSCfgDesc
  *         Return configuration descriptor
  * @param  speed : current device speed
  * @param  length : pointer data length
  * @retval pointer to descriptor buffer
  */
static uint8_t  *USBD_CDC_GetFSCfgDesc (uint16_t *length)
{
  *length = sizeof (USBD_CDC_CfgFSDesc);
  return USBD_CDC_CfgFSDesc;
}

/**
  * @brief  USBD_CDC_GetHSCfgDesc
  *         Return configuration descriptor
  * @param  speed : current device speed
  * @param  length : pointer data length
  * @retval pointer to descriptor buffer
  */
static uint8_t  *USBD_CDC_GetHSCfgDesc (uint16_t *length)
{
  *length = sizeof (USBD_CDC_CfgHSDesc);
  return USBD_CDC_CfgHSDesc;
}

/**
  * @brief  USBD_CDC_GetCfgDesc
  *         Return configuration descriptor
  * @param  speed : current device speed
  * @param  length : pointer data length
  * @retval pointer to descriptor buffer
  */
static uint8_t  *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
{
  *length = sizeof (USBD_CDC_OtherSpeedCfgDesc);
  return USBD_CDC_OtherSpeedCfgDesc;
}

/**
* @brief  DeviceQualifierDescriptor
*         return Device Qualifier descriptor
* @param  length : pointer data length
* @retval pointer to descriptor buffer
*/
uint8_t  *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length)
{
  *length = sizeof (USBD_CDC_DeviceQualifierDesc);
  return USBD_CDC_DeviceQualifierDesc;
}

/**
* @brief  USBD_CDC_RegisterInterface
  * @param  pdev: device instance
  * @param  fops: CD  Interface callback
  * @retval status
  */
uint8_t  USBD_CDC_RegisterInterface  (USBD_HandleTypeDef   *pdev,
                                      USBD_CDC_ItfTypeDef *fops)
{
  uint8_t  ret = USBD_FAIL;

  if(fops != NULL)
  {
    pdev->pUserData= fops;
    ret = USBD_OK;
  }

  return ret;
}

/**
  * @brief  USBD_CDC_SetTxBuffer
  * @param  pdev: device instance
  * @param  pbuff: Tx Buffer
  * @retval status
  */
uint8_t  USBD_CDC_SetTxBuffer  (USBD_HandleTypeDef   *pdev,
                                uint8_t  *pbuff,
                                uint16_t length)
{
  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

  hcdc->TxBuffer = pbuff;
  hcdc->TxLength = length;

  return USBD_OK;
}


/**
  * @brief  USBD_CDC_SetRxBuffer
  * @param  pdev: device instance
  * @param  pbuff: Rx Buffer
  * @retval status
  */
uint8_t  USBD_CDC_SetRxBuffer  (USBD_HandleTypeDef   *pdev,
                                   uint8_t  *pbuff)
{
  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

  hcdc->RxBuffer = pbuff;

  return USBD_OK;
}

/**
  * @brief  USBD_CDC_TransmitPacket
  *         Transmit packet on IN endpoint
  * @param  pdev: device instance
  * @retval status
  */
uint8_t  USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
{
  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

  if(pdev->pClassData != NULL)
  {
    if(hcdc->TxState == 0U)
    {
      /* Tx Transfer in progress */
      hcdc->TxState = 1U;

      /* Update the packet total length */
      pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength;

      /* Transmit next packet */
      USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer,
                       (uint16_t)hcdc->TxLength);

      return USBD_OK;
    }
    else
    {
      return USBD_BUSY;
    }
  }
  else
  {
    return USBD_FAIL;
  }
}


/**
  * @brief  USBD_CDC_ReceivePacket
  *         prepare OUT Endpoint for reception
  * @param  pdev: device instance
  * @retval status
  */
uint8_t  USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
{
  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

  /* Suspend or Resume USB Out process */
  if(pdev->pClassData != NULL)
  {
    if(pdev->dev_speed == USBD_SPEED_HIGH  )
    {
      /* Prepare Out endpoint to receive next packet */
      USBD_LL_PrepareReceive(pdev,
                             CDC_OUT_EP,
                             hcdc->RxBuffer,
                             CDC_DATA_HS_OUT_PACKET_SIZE);
    }
    else
    {
      /* Prepare Out endpoint to receive next packet */
      USBD_LL_PrepareReceive(pdev,
                             CDC_OUT_EP,
                             hcdc->RxBuffer,
                             CDC_DATA_FS_OUT_PACKET_SIZE);
    }
    return USBD_OK;
  }
  else
  {
    return USBD_FAIL;
  }
}
/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
